<template>
	<div>
		<div class="h2">问卷结果详细</div>
		<div id="components-form-demo-advanced-search" style="display: none;">
			<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
				<a-row :gutter="24">
					<!-- <a-col :span="8">
						<a-form-item label="关键字">
							<a-input autocomplete="off" class="field-right" placeholder="请输入关键字搜索"
								v-decorator="[`key`]" />
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="问卷" style="display: flex;align-items: center;" class="lableBox">
							<a-select :allowClear="true" v-decorator="['headMasterEvaluationID']" placeholder="全部"
								optionFilterProp="children" showSearch>
								<a-select-option v-for="(item, index) in EvaluationData" :key="index" :value="item.ID">
									{{ item.Name }}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>

					<a-col :span="8">
						<a-form-item label="学期">
							<a-select :allowClear="true" v-decorator="['semesterID']" placeholder="全部"
								optionFilterProp="children" showSearch>
								<a-select-option v-for="(item, index) in SemesterList" :key="index" :value="item.ID">
									{{ item.Name }}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="时间">
							<a-range-picker v-decorator="['data']" format="YYYY-MM" />
						</a-form-item>
					</a-col>
					<ClubSearch :span="8" label="班级" name="classID" ref="classID" @tap="searchValueFun"></ClubSearch>
					<a-col :span="8">
						<a-form-item label="部门">
							<a-select :allowClear="true" v-decorator="['departCode']" placeholder="全部" optionFilterProp="children" showSearch>
								<a-select-option v-for="(item, index) in DepartCodeList" :key="index" :value="item.Code">{{ item.Name }}</a-select-option>
							</a-select>
						</a-form-item>
					</a-col> -->
					<a-col :span="8">
						<a-form-item label="申请人">
							<template>
								<a-select v-decorator="['addUserNo']" showSearch optionFilterProp="children"
									style="width: 100%" :showArrow="false" @search="fetchmember"
									:filterOption="filterOption" placeholder="请输入关键字进行搜索" allowClear>
									<a-select-option v-for="(item, index) in memberList" :key="item.UserNo">
										{{ item.UserNo }}&nbsp;|&nbsp;{{ item.Name }}
									</a-select-option>
								</a-select>
							</template>
						</a-form-item>
					</a-col>
					<!-- <a-col :span="8">
						<a-form-item label="班主任">
							<template>
								<a-select v-decorator="['headMaster']" showSearch optionFilterProp="children"
									style="width: 100%" :showArrow="false" @search="fetchmemberHead"
									:filterOption="filterOption" placeholder="请输入关键字进行搜索" allowClear>
									<a-select-option v-for="(item, index) in memberList2" :key="item.UserNo">
										{{ item.UserNo }}&nbsp;|&nbsp;{{ item.Name }}
									</a-select-option>
								</a-select>
							</template>
						</a-form-item>
					</a-col> -->
				</a-row>
			</a-form>
		</div>
		<a-button-group size="default" class="option" v-if="false">
			<a-button type="primary" @click="handleSearch">搜索</a-button>
			<a-button @click="handleReset">重置</a-button>
			<!-- <a-button type="primary" @click="addList">新增</a-button> -->
			<!-- 
			<a-button type="primary" @click="exportList()">导出</a-button> -->
		</a-button-group>
		<div>
			<el-table :data="data"  v-loading="loading"  default-expand-all  @expand-change="hangClick" :max-height="tableHeight" highlight-current-row
				style="width: 100%;">
				<el-table-column type="expand" prop="children">
					<template scope="scope">
						<el-table :data="scope.row.items1">
							<el-table-column type="index" label="序号" width="60" fixed="left"></el-table-column>
							<el-table-column prop="EvaluationSubjectName" label="题目"   width="240"></el-table-column>
							<el-table-column prop="Type" label="类型"   width="100">
								<template slot-scope="scope1">
									{{scope1.row.Type==1?'单选':scope1.row.Type==2?'多选':scope1.row.Type==3?'填空题':''}}
									</template>
							</el-table-column>
							<el-table-column prop="Score" label="结果"  show-overflow-tooltip>
								<template slot-scope="scope1">
									<div v-for="(item,index) in scope1.row.record">
										<div v-if="scope1.row.Type!=3">
											选项：{{item.EvaluationSubjectItemName}}</br>
											分值：{{item.Score}}</br>
										<!-- 	评价：{{item.Content}}</br> -->
										</div>
										<div v-else> 
											答案:{{item.Content}}</br>
										</div>
										
									</div>
									<div>
										
									</div>
								</template>
							</el-table-column>
						</el-table>
					</template>
				</el-table-column>
				<el-table-column type="index" label="序号" width="60" fixed="left"></el-table-column>
				<el-table-column prop="AddUserNo" label="学生/老师">
					<template slot-scope="scope">
						<a-tag color="green">{{ scope.row.AddUserNo }}/{{ scope.row.AddUserName }}
						</a-tag>
					</template>
				</el-table-column>
			</el-table>
			<!-- <el-table :data="newData" v-loading="loading" @expand-change="hangClick" :max-height="tableHeight"
				highlight-current-row style="width: 100%;">
				<el-table-column type="index" label="序号" width="60" fixed="left"></el-table-column>
				<el-table-column prop="EvaluationSubjectName" label="题目"></el-table-column>
				<el-table-column prop="EvaluationSubjectName" label="类型">
					<template slot-scope="scope1">
						{{scope1.row.Type==1?'单选':scope1.row.Type==2?'多选':scope1.row.Type==3?'填空题':''}}
					</template>
				</el-table-column>
				<el-table-column prop="Score" label="结果" show-overflow-tooltip>
					<template slot-scope="scope1">
						<div v-for="(item,index) in scope1.row.record">
							<div v-if="scope1.row.Type!=3">
								选项：{{item.EvaluationSubjectItemName}}</br>
								分值：{{item.Score}}</br>
								评价：{{item.Content}}</br>
							</div>
							<div v-else>
								答案:{{item.Content}}</br>
							</div>
						</div>
					</template>
				</el-table-column>
				<el-table-column prop="TotalScore" label="总分"></el-table-column>
				
			</el-table> -->
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="pagination.currentPage" :page-sizes="pagination.pageSizeOptions"
				:page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper"
				:total="pagination.total"></el-pagination>
		</div>
		<add :text="text" :DepartCodeList="DepartCodeList" :ClassList="ClassList" v-show="addIf" @closeFun="closeFun">
		</add>
	</div>
</template>

<script>
	import Cache from '@/utils/cache';
	import add from './add';
	import Func from '@/utils/func';
	import moment from 'moment';
	import ClubSearch from '@/components/SearchForm/ClubSearch.vue'
	import {
		ManageEvaluationResultDoGetResultDetailPageList,
		ManageHeadMasterEvaluationDoDelete,
		GetDepartList,
		GetClassList,
		DoUnbundTeacher,
		DoEnableTeacher,
		DoGetSemesterListCommon,
		CommonDoGetHeadMasterEvaluationList,
		GetUserList
	} from '@/api/follow';
	const data = [];
	export default {
		components: {
			add,
			ClubSearch
		},
		data() {
			return {
				memberList2: [],
				memberList: [],
				SemesterList: [],
				EvaluationData: [],
				data,
				newData: [],
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				addIf: false,
				text: {},
				visible: false,
				confirmLoading: false,
				itemId: '',
				gradeYear: null,
				yearPickShow: false,
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				pages: {
					pageIndex: 1,
					pageSize: 20
				},
				tableHeight: parseFloat(window.innerHeight - 160),
				ClassList: [],
				DepartCodeList: [],
				requestUrl: this.global.requestUrl,
				token: Cache.get('token')
			};
		},
		computed: {},
		created() {
			this.getList();
			// this.getOtherList();
		},
		mounted() {},
		methods: {
			hangClick(e) {
				console.log(e);
			},
			moment,
			exportList() {
				this.form.validateFields((error, values) => {
					let data = {};
					data.key = values.key;
					data.departCode = values.departCode;
					let hrefUrl = this.requestUrl + 'Manage/Teacher/DoExport?userToken=' + encodeURIComponent(this
						.token);
					let hrefStr = '';
					for (let key in data) {
						if (data[key]) {
							hrefStr += key + '=' + data[key] + '&';
						}
					}
					window.open(hrefUrl + '&' + hrefStr, '_blank');
				});
			},
			filterOption(input, option) {
				return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0;
			},
			async fetchmemberHead(value) {
				// let myReg = /^[^a-zA-Z]+$/;
				if (value && value.length > 1) {
					let data = {};
					data.key = value;
					data.top = 20;
					let res = await GetUserList(data);
					this.memberList2 = res.data.data;
				}
			},
			async fetchmember(value) {
				// let myReg = /^[^a-zA-Z]+$/;
				if (value && value.length > 1) {
					let data = {};
					data.key = value;
					data.top = 20;
					let res = await GetUserList(data);
					this.memberList = res.data.data;
				}
			},
			searchValueFun(name, value) {
				this.values = {
					...this.values,
					[name]: value
				}
			},
			handleOpenChange(status) {
				this.yearPickShow = status;
			},
			handlePanelChange(value, mode) {
				this.gradeYear = moment(value).format('YYYY');
				this.yearPickShow = false;
			},
			yearChange(date, dateString) {
				if (!date) {
					this.gradeYear = null;
				}
			},
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					if (values.data && values.data.length > 0) {
						values.startTime = values.data[0].format('YYYY-MM') + '-01'
						values.endTime = values.data[1].format('YYYY-MM') + '-01'
					}
					this.values = values;
					this.getList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.gradeYear = null;
				this.getList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.departCode = this.$route.query.departCode;
				data.classID = this.$route.query.classID;
				data.startTime = this.$route.query.startTime;
				data.endTime = this.$route.query.endTime;

				data.evaluatTime = this.$route.query.evaluatTime;
				data.semesterID = this.$route.query.semesterID;
				data.headMaster = this.$route.query.headMaster;
				data.evaluationResultID = this.$route.query.ID;
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				let res = await ManageEvaluationResultDoGetResultDetailPageList(data);
				this.loading = false;
				this.data = res.data.data;
				this.newData = []
				res.data.data.forEach(item => {
					item.items1.forEach(item2=>{
						let num = 0
						item2.record.forEach(item3=>{
							num+=Number(item3.Score)
						})
						item2.TotalScore = num
						this.newData.push(item2)
					})
					
				})
				const pagination = {
					...this.pagination
				};
				pagination.total = res.data.pageInfo.TotalItemCount;
				this.pagination = pagination;
			},
			async getOtherList() {
				let res = await GetClassList();
				this.ClassList = res.data.data;
				let res1 = await GetDepartList();
				this.DepartCodeList = res1.data.data;
				let res3 = await DoGetSemesterListCommon();
				this.SemesterList = res3.data.data;
				let res2 = await CommonDoGetHeadMasterEvaluationList();
				this.EvaluationData = res2.data.data;

			},
			addList() {
				this.text = {};
				this.addIf = !this.addIf;
			},
			modifyList(text) {
				text = Object.assign(text, {
					time: new Date()
				});
				this.addIf = !this.addIf;
				this.text = text;
			},
			deleteList(text, type) {
				let that = this;
				this.$confirm({
					title: '提示',
					content: type == 1 ? `您确定删除该问卷吗？` : type == 2 ? `您确定要解绑该教师的微信吗？` : `您确定要修改该老师的状态吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id = text.ID;
						let res = type == 1 ? await ManageHeadMasterEvaluationDoDelete(data) : type == 2 ?
							await DoUnbundTeacher(data) : await DoEnableTeacher(data);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			seeList(text, name) {
				this.$router.push({
					name: name,
					query: {
						ID: text.ID,
						Name: text.Name,
						UserNo: text.UserNo
					}
				});
			},
			closeFun() {
				this.addIf = false;
				this.getList();
			}
		}
	};
</script>

<style lang="less" scoped>
	/deep/.ant-form-item {
		display: flex;
		margin-bottom: 10px !important;
	}

	/deep/.ant-form-item-label {
		width: 80px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		text-align: right;
	}

	/deep/.ant-form-item-control-wrapper {
		flex: 1;
	}

	/deep/.ant-calendar-picker {
		width: 100%;
	}
</style>
